﻿using Google.Protobuf;
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public static class CommonUtil
{
    static DateTime m_StartTime;
    
    public static void Init()
    {
        m_StartTime = DateTime.Now;
    }

    public static EMessageType GetMessageType(this IMessage msg)
    {
        return MessageManager.Instance.GetMessageType(msg);
    }

    public static float GetCurRealTime()
    {
        return System.DateTime.Now.Ticks / (float)System.TimeSpan.TicksPerSecond;
    }

    public static float GetCurElapsedTime()
    {
        return (float)(System.DateTime.Now - m_StartTime).TotalSeconds;
    }

    public static uint GetSeqID(this IMessage msg)
    {
        var v = msg.GetType().GetProperty("Msg").GetValue(msg, null);
        if (v == null)
        {
            return 0;
        }

        return (v as BaseMessage).SeqId;
    }
}
